#ifndef MUSICLIST_H
#define MUSICLIST_H

#include <QVector>
#include <QUrl>
#include <QSet>
#include "music.h"

typedef QVector<Music>::iterator iterator;
typedef QVector<Music>::reverse_iterator reverse_iterator;

// 管理所有的歌曲对应的Music对象
class MusicList
{
public:
    MusicList();

    QList<QUrl> addMusicsByUrl(const QList<QUrl>& musicUrls);

    iterator findMusicByMusicUrl(const QUrl& musicUrl);

    iterator begin();
    iterator end();
    reverse_iterator rbegin();
    reverse_iterator rend();

    void readFromDB();
    void writeToDB();
private:
    QVector<Music> musicList;
    QHash<QUrl, int> musicIndex;  // 保存歌曲路径和对应下标，用于查找和防止歌曲文件重复加载
};

#endif // MUSICLIST_H
